package com.ly.lypopupwindowdemo.views;

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Picture;
import android.support.annotation.Nullable;
import android.util.AttributeSet;
import android.view.View;

/**
 * Created by liying on 2018/1/26.
 */

public class DrawPicture extends View {
    private  Picture mPicture;



    public DrawPicture(Context context) {
        super(context);

        mPicture = new Picture();
        Canvas recordingCanvas = mPicture.beginRecording(500,500);
        //将坐标系的原点移动到(450,650)
        recordingCanvas.translate(450,650);
        //创建画笔
        Paint paint = new Paint();
        paint.setColor(Color.BLUE);
        paint.setStyle(Paint.Style.FILL);

        //绘制圆
        recordingCanvas.drawCircle(0,0,100,paint);
        //结束录制
        mPicture.endRecording();
        //将存储在Picture中的绘制内容绘制出来
        //有三种方法
        /**
         * Picture.draw(Canvas canvas)
         * Canvas.drawPicture()
         * PictureDrawable.draw()
         */

    }

    public DrawPicture(Context context,  AttributeSet attrs) {
        super(context, attrs);
    }

    public DrawPicture(Context context,  AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
    }

    @Override
    protected void onDraw(Canvas canvas) {
        super.onDraw(canvas);
        mPicture.draw(canvas);
    }
}
